package com.wake.mycomposebook.ui.home.modifier

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.clickable
import androidx.compose.material.Icon
import androidx.compose.material.TopAppBar
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.wake.mycomposebook.ui.home.layouts.*
import com.wake.mycomposebook.ui.home.layouts.advlist.swpier.MySwiper2
import com.wake.mycomposebook.ui.home.layouts.advlist.swpier.MySwiper3
import com.wake.mycomposebook.ui.home.modifier.m.MyModifier
import com.wake.theme.modifier.MyComposeBookMaterial3Theme

/**
 *@author created by WA03675
 *@date  2022-04-18 09:59
 *@des
 */
class ModifierActivity : ComponentActivity() {
    private val type: String by lazy {
        return@lazy intent.getStringExtra(TYPE) ?: ""
    }
    private val dark: Boolean by lazy {
        return@lazy intent.getBooleanExtra(DARK, false)
    }


    companion object {
        private const val TYPE = "type"
        const val DARK = "isDark"
        fun newIntent(context: Context, type: String, isDark: Boolean) {
            val intent = Intent(context, ModifierActivity::class.java)
            intent.putExtra(TYPE, type)
            intent.putExtra(DARK, isDark)
            context.startActivity(intent)
        }
    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MyComposeBookMaterial3Theme(dark) {
                ModifierScreen()
            }
        }
    }


    @Composable
    fun ModifierScreen() {

        androidx.compose.material.Scaffold(
            topBar = {
                TopAppBar(
                    title = {
                        Text(type, style = MaterialTheme.typography.titleLarge, color = MaterialTheme.colorScheme.background)
                    },
                    navigationIcon = {
                        Icon(imageVector = Icons.Default.ArrowBack, contentDescription = null, modifier = Modifier.clickable { finish() })
                    }
                )
            },

            content = {
                when (type) {
                    "Modifiers" -> {
                        MyModifier()
                    }
                    "Layouts" -> {
                        MyLayouts()
                    }
                    "Constraint Layout" -> {
                        MyConstrainLayout()
                    }
                    "Motion Layout" -> {
                        MyMotionLayout()
                    }
                    "Advance Lists" -> {
                        MyAdvList()
                    }

                    "Custom Fling" -> {

                    }
                    "Compose X Android views" -> {
                        MyAndroidView()
                    }
                    "Carousel" -> {
//                        MySwiper()
//                        MySwiper2()
                        MySwiper3()
                    }
                    "Dialogs" -> {
                        MyDialog()
                    }
                    "TabLayout" -> {

                    }
                    "BottomSheets" -> {

                    }
                    "Pull refresh demos" -> {

                    }

                    else -> {}
                }
            }
        )


    }

}